package com.fanshuai.lifecycle.aware;

import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/**
 * 获取全局Environment
 */
@Component
public class DemoEnvironment implements EnvironmentAware {
    private Environment environment;

    @Override
    public void setEnvironment(Environment environment) {
        this.environment = environment;
        System.out.println("environment=" + environment);
        System.out.println("profiles=" + environment.getActiveProfiles());
        System.out.println("default profiles=" + environment.getDefaultProfiles());
    }

    public Environment getEnvironment() {
        return environment;
    }
}
